<template>
	<view class="container">
		<view class="tx">
			<image src="/static/my.png" style="width: 100px; height: 100px; "></image>
		</view>
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="user.name" placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput type="password" v-model="user.password" placeholder="请输入密码" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="login">登录</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					name: '',
					password: ''
				}
			}
		},
		methods: {
			login(e) {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/login',
					method: 'POST',
					data: this.user,
					success: res => {
						console.log(e);
						if (res.data.success == true) {
							uni.showToast({
								title: '欢迎您' + this.user.name
							});
							uni.setStorageSync("userinfo",res.data.data)
							uni.switchTab({
								url:"/pages/my/my"
							})
						} else {
							uni.showToast({
								title: '用户身份登录失败',
								icon: 'none'
							});
						}
						
					},
					fail: () => {
						uni.showToast({
							title: '真糟糕！您的网络被外星人偷走了！！！',
							icon: 'none'
						});
					},
					complete: () => {}
				});
				// console.log(e);
				// uni.showToast({
				// 	title: this.user.username+'登录成功'
				// });
			}
		}
	}
</script>

<style>
	.tx {
		margin-top: 30px;
		margin-bottom: 50px;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>